#!/usr/bin/python
'''
Builds a histogram from a bunch of numbers.
'''
import sys
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import numpy as np

# parameters.
in_file = sys.argv[1]
bin_size = int(sys.argv[2])
normed = False

# read in file.
print "reading file."
fin = open(in_file)
lines = fin.readlines()
fin.close()

# pull out numbers.
print "parsing file."
x = np.zeros(len(lines),dtype=np.int)
for i in range(len(lines)):
	x[i] = int(lines[i].strip())


# the histogram of the data
n, bins, patches = plt.hist(x, bins=bin_size, normed=True, facecolor='green')


# add a 'best fit' line
#y = mlab.normpdf( bins, mu, sigma)
#l = plt.plot(bins, y, 'r--', linewidth=1)

#plt.xlabel('Smarts')
#plt.ylabel('Probability')
#plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
plt.grid(True)

plt.show()

